package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MyItem;
import com.ruoyi.system.service.IMyItemService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物料产品Controller
 * 
 * @author t382
 * @date 2025-05-07
 */
@RestController
@RequestMapping("/ruoyidata/item")
public class MyItemController extends BaseController
{
    @Autowired
    private IMyItemService myItemService;

    /**
     * 查询物料产品列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyidata:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyItem myItem)
    {
        startPage();
        List<MyItem> list = myItemService.selectMyItemList(myItem);
        return getDataTable(list);
    }

    /**
     * 导出物料产品列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyidata:item:export')")
    @Log(title = "物料产品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MyItem myItem)
    {
        List<MyItem> list = myItemService.selectMyItemList(myItem);
        ExcelUtil<MyItem> util = new ExcelUtil<MyItem>(MyItem.class);
        util.exportExcel(response, list, "物料产品数据");
    }

    /**
     * 获取物料产品详细信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyidata:item:query')")
    @GetMapping(value = "/{itemId}")
    public AjaxResult getInfo(@PathVariable("itemId") Long itemId)
    {
        return success(myItemService.selectMyItemByItemId(itemId));
    }

    /**
     * 新增物料产品
     */
    @PreAuthorize("@ss.hasPermi('ruoyidata:item:add')")
    @Log(title = "物料产品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyItem myItem)
    {
        return toAjax(myItemService.insertMyItem(myItem));
    }

    /**
     * 修改物料产品
     */
    @PreAuthorize("@ss.hasPermi('ruoyidata:item:edit')")
    @Log(title = "物料产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyItem myItem)
    {
        return toAjax(myItemService.updateMyItem(myItem));
    }

    /**
     * 删除物料产品
     */
    @PreAuthorize("@ss.hasPermi('ruoyidata:item:remove')")
    @Log(title = "物料产品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{itemIds}")
    public AjaxResult remove(@PathVariable Long[] itemIds)
    {
        return toAjax(myItemService.deleteMyItemByItemIds(itemIds));
    }
}
